import collections
class Solution(object):
    def hasGroupsSizeX(self, deck):
        """
        :type deck: List[int]
        :rtype: bool
        """
        c = collections.Counter(deck)
        d = min(list(c.values()))
        if d == 1:
            return False
        if len(c) == 1:
            return True
        st = []
        for i in range(2, int(d ** 0.5) + 1):
            if d % i == 0:
                st.append(i)
                st.append(d // i)
        st.append(d)
        for value in st:
            flag = True
            for key in c:
                if c[key] % value != 0:
                    flag = False
                    break
            if flag:
                return True
        return False


data = Solution()
deck = [1, 2, 3, 4, 4, 3, 2, 1]
print(data.hasGroupsSizeX(deck))
